package br.unicamp.ic.lis.docseaservice.model.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;

public class SpecialQueryRunner extends QueryRunner {

	@Override
	public int update(Connection conn, String sql, Object... params)
			throws SQLException {
		ResultSet generatedKeys = null;

		PreparedStatement stmt = null;
		int rows = 0;

		try {
			stmt = this.prepareStatement(conn, sql);
			this.fillStatement(stmt, params);
			rows = stmt.executeUpdate();

			generatedKeys = stmt.getGeneratedKeys();
			if (generatedKeys.next()) {
				// return generatedKeys.getObject(1);
			} else {
				// return null;
			}

		} catch (SQLException e) {
			this.rethrow(e, sql, params);

		} finally {
			close(stmt);
		}

		return rows;
	}
}
